using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using SFS.SampleApp.Web.Mvc.Resources;
using System.Runtime.Serialization;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Extensions;
using BO = SFS.SampleApp.BusinessObjects;
using System.Web.Mvc;
using SFSdotNet.Framework.Web.Mvc.Validation;
using SFSdotNet.Framework.Web.Mvc.Models;
using SFSdotNet.Framework.Web.Mvc.Resources;
using SFSdotNet.Framework.Entities.Metadata;


namespace SFS.SampleApp.Web.Mvc.Models.SalesOrderHeaders 
{
	public partial class SalesOrderHeaderModel: ModelBase{
		public SalesOrderHeaderModel()
        {
		}
		public override string Id
        {
            get
            {
                return this.SalesOrderID.ToString();
            }
        }
			
			
        public override string ToString()
        {
		
            return this.SalesOrderNumber.ToString();
		
        }    
			
	
		[SystemProperty()]		
		public Int32? SalesOrderID{ get; set; }
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_REVISIONNUMBER_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("REVISIONNUMBER", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Byte   RevisionNumber { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_ORDERDATE_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("ORDERDATE", NameResourceType=typeof(SalesOrderHeaderResources))]
	public DateTime   OrderDate { get; set; }
	public string OrderDateText {
        get {
            if (OrderDate != null)
			
                return ((DateTime)OrderDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.OrderDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_DUEDATE_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("DUEDATE", NameResourceType=typeof(SalesOrderHeaderResources))]
	public DateTime   DueDate { get; set; }
	public string DueDateText {
        get {
            if (DueDate != null)
			
                return ((DateTime)DueDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.DueDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("SHIPDATE", NameResourceType=typeof(SalesOrderHeaderResources))]
	public DateTime  ? ShipDate { get; set; }
	public string ShipDateText {
        get {
            if (ShipDate != null)
			
                return ((DateTime)ShipDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ShipDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_STATUS_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("STATUS", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Byte   Status { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_ONLINEORDERFLAG_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("ONLINEORDERFLAG", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Boolean   OnlineOrderFlag { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_SALESORDERNUMBER_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("SALESORDERNUMBER", NameResourceType=typeof(SalesOrderHeaderResources))]
	public String   SalesOrderNumber { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("PURCHASEORDERNUMBER", NameResourceType=typeof(SalesOrderHeaderResources))]
	public String   PurchaseOrderNumber { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("ACCOUNTNUMBER", NameResourceType=typeof(SalesOrderHeaderResources))]
	public String   AccountNumber { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_SHIPMETHOD_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("SHIPMETHOD", NameResourceType=typeof(SalesOrderHeaderResources))]
	public String   ShipMethod { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[LocalizedDisplayName("CREDITCARDAPPROVALCODE", NameResourceType=typeof(SalesOrderHeaderResources))]
	public String   CreditCardApprovalCode { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_SUBTOTAL_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("SUBTOTAL", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Decimal   SubTotal { get; set; }
    public string SubTotalText {
        get {
				return SubTotal.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_TAXAMT_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("TAXAMT", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Decimal   TaxAmt { get; set; }
    public string TaxAmtText {
        get {
				return TaxAmt.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_FREIGHT_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("FREIGHT", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Decimal   Freight { get; set; }
    public string FreightText {
        get {
				return Freight.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_TOTALDUE_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[LocalizedDisplayName("TOTALDUE", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Decimal   TotalDue { get; set; }
    public string TotalDueText {
        get {
				return TotalDue.ToString();
				
        }
        
    }

		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[DataType("RichEditorAdvanced")]
	[LocalizedDisplayName("COMMENT", NameResourceType=typeof(SalesOrderHeaderResources))]
	public String   Comment { get; set; }
		
		
	
[Exportable()]
		
	[RelationFilterable()]
	[SystemProperty()]
	[LocalizedDisplayName("ROWGUID", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Guid   rowguid { get; set; }
		
		
	
[Exportable()]
	
	    [Required(AllowEmptyStrings=false, ErrorMessageResourceName="VAL_MODIFIEDDATE_REQUIRED", ErrorMessageResourceType=typeof(SalesOrderHeaderResources))]
		
	[RelationFilterable()]
	[DateTime(true, false, null)]	
	[LocalizedDisplayName("MODIFIEDDATE", NameResourceType=typeof(SalesOrderHeaderResources))]
	public DateTime   ModifiedDate { get; set; }
	public string ModifiedDateText {
        get {
            if (ModifiedDate != null)
			
                return ((DateTime)ModifiedDate).ToShortDateString();
            else
                return String.Empty;
        }
				set{
				this.ModifiedDate = Convert.ToDateTime(value);
    }
		}
		
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.AddressesController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "AddressLine1", DataPropertyValue = "AddressID", FiltrablePropertyPathName="Address.AddressID")]	

	[LocalizedDisplayName("ADDRESS", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Int32  ? FkAddress { get; set; }
		[LocalizedDisplayName("ADDRESS", NameResourceType=typeof(SalesOrderHeaderResources))]
	[Exportable()]
	public string  FkAddressText { get; set; }
    public string FKAddressSafeKey { get; set; }

	
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.AddressesController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "AddressLine1", DataPropertyValue = "AddressID", FiltrablePropertyPathName="Address1.AddressID")]	

	[LocalizedDisplayName("ADDRESS1", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Int32  ? FkAddress1 { get; set; }
		[LocalizedDisplayName("ADDRESS1", NameResourceType=typeof(SalesOrderHeaderResources))]
	[Exportable()]
	public string  FkAddress1Text { get; set; }
    public string FKAddress1SafeKey { get; set; }

	
		
	
[Exportable()]
		
	[RelationFilterable(DataClassProvider = typeof(Controllers.CustomersController), GetByKeyMethod="GetByKey", GetAllMethod = "GetAll", DataPropertyText = "Title", DataPropertyValue = "CustomerID", FiltrablePropertyPathName="Customer.CustomerID")]	

	[LocalizedDisplayName("CUSTOMER", NameResourceType=typeof(SalesOrderHeaderResources))]
	public Int32  ? FkCustomer { get; set; }
		[LocalizedDisplayName("CUSTOMER", NameResourceType=typeof(SalesOrderHeaderResources))]
	[Exportable()]
	public string  FkCustomerText { get; set; }
    public string FKCustomerSafeKey { get; set; }

	
		
		
		[LocalizedDisplayName("SALESORDERDETAILS", NameResourceType=typeof(SalesOrderHeaderResources))]
		[RelationFilterable(IsNavigationPropertyMany=true, FiltrablePropertyPathName="SalesOrderDetails.Count()", ModelPartialType="SalesOrderDetails.SalesOrderDetail")]
        public List<SalesOrderDetails.SalesOrderDetailModel> SalesOrderDetails { get; set; }			
	
	public override string SafeKey
   	{
		get
        {
			if(this.SalesOrderID != null)
				return SFSdotNet.Framework.Entities.Utils.GetKey(this ,"SalesOrderID").Replace("/","-");
			else
				return String.Empty;
		}
    }		
		public void Bind(SalesOrderHeaderModel model){
            
		this.SalesOrderID = model.SalesOrderID;
		this.RevisionNumber = model.RevisionNumber;
		this.OrderDate = model.OrderDate;
		this.DueDate = model.DueDate;
		this.ShipDate = model.ShipDate;
		this.Status = model.Status;
		this.OnlineOrderFlag = model.OnlineOrderFlag;
		this.SalesOrderNumber = model.SalesOrderNumber;
		this.PurchaseOrderNumber = model.PurchaseOrderNumber;
		this.AccountNumber = model.AccountNumber;
		this.ShipMethod = model.ShipMethod;
		this.CreditCardApprovalCode = model.CreditCardApprovalCode;
		this.SubTotal = model.SubTotal;
		this.TaxAmt = model.TaxAmt;
		this.Freight = model.Freight;
		this.TotalDue = model.TotalDue;
		this.Comment = model.Comment;
		this.rowguid = model.rowguid;
		this.ModifiedDate = model.ModifiedDate;
        }

        public BusinessObjects.SalesOrderHeader GetBusinessObject()
        {
            BusinessObjects.SalesOrderHeader result = new BusinessObjects.SalesOrderHeader();
	if (this.SalesOrderID != null )
				result.SalesOrderID = (Int32)this.SalesOrderID;
				
	if (this.RevisionNumber != null )
				result.RevisionNumber = (Byte)this.RevisionNumber;
				
				result.OrderDate = (DateTime)this.OrderDate;		
				
				result.DueDate = (DateTime)this.DueDate;		
				
				if(this.ShipDate != null)
					if (this.ShipDate != null)
				result.ShipDate = (DateTime)this.ShipDate;		
				
	if (this.Status != null )
				result.Status = (Byte)this.Status;
				
	if (this.OnlineOrderFlag != null )
				result.OnlineOrderFlag = (Boolean)this.OnlineOrderFlag;
				
	if (this.SalesOrderNumber != null )
				result.SalesOrderNumber = (String)this.SalesOrderNumber.Trim().Replace("\t", String.Empty);
				
	if (this.PurchaseOrderNumber != null )
				result.PurchaseOrderNumber = (String)this.PurchaseOrderNumber.Trim().Replace("\t", String.Empty);
				
	if (this.AccountNumber != null )
				result.AccountNumber = (String)this.AccountNumber.Trim().Replace("\t", String.Empty);
				
	if (this.ShipMethod != null )
				result.ShipMethod = (String)this.ShipMethod.Trim().Replace("\t", String.Empty);
				
	if (this.CreditCardApprovalCode != null )
				result.CreditCardApprovalCode = (String)this.CreditCardApprovalCode.Trim().Replace("\t", String.Empty);
				
	if (this.SubTotal != null )
				result.SubTotal = (Decimal)this.SubTotal;
				
	if (this.TaxAmt != null )
				result.TaxAmt = (Decimal)this.TaxAmt;
				
	if (this.Freight != null )
				result.Freight = (Decimal)this.Freight;
				
	if (this.TotalDue != null )
				result.TotalDue = (Decimal)this.TotalDue;
				
	if (this.Comment != null )
				result.Comment = (String)this.Comment.Trim().Replace("\t", String.Empty);
				
	if (this.rowguid != null )
				result.rowguid = (Guid)this.rowguid;
				
				result.ModifiedDate = (DateTime)this.ModifiedDate;		
				
			
			if(this.FkAddress != null )
	result.Address = new BusinessObjects.Address() { AddressID= (Int32)this.FkAddress };
				
			
			if(this.FkAddress1 != null )
	result.Address1 = new BusinessObjects.Address() { AddressID= (Int32)this.FkAddress1 };
				
	result.Customer = new BusinessObjects.Customer() { CustomerID= (Int32)this.FkCustomer };
				



            return result;
        }
        public void Bind(BusinessObjects.SalesOrderHeader businessObject)
        {
            
			this.SalesOrderID = businessObject.SalesOrderID;
				
			this.RevisionNumber = businessObject.RevisionNumber;
				
				this.OrderDate = (DateTime)businessObject.OrderDate;
				this.DueDate = (DateTime)businessObject.DueDate;
				if (businessObject.ShipDate != null )
				this.ShipDate = (DateTime)businessObject.ShipDate;
			this.Status = businessObject.Status;
				
			this.OnlineOrderFlag = businessObject.OnlineOrderFlag;
				
			this.SalesOrderNumber = businessObject.SalesOrderNumber != null ? businessObject.SalesOrderNumber.Trim().Replace("\t", String.Empty) : "";
				
				
	if (businessObject.PurchaseOrderNumber != null )
				this.PurchaseOrderNumber = (String)businessObject.PurchaseOrderNumber;
				
	if (businessObject.AccountNumber != null )
				this.AccountNumber = (String)businessObject.AccountNumber;
			this.ShipMethod = businessObject.ShipMethod != null ? businessObject.ShipMethod.Trim().Replace("\t", String.Empty) : "";
				
				
	if (businessObject.CreditCardApprovalCode != null )
				this.CreditCardApprovalCode = (String)businessObject.CreditCardApprovalCode;
			this.SubTotal = businessObject.SubTotal;
				
			this.TaxAmt = businessObject.TaxAmt;
				
			this.Freight = businessObject.Freight;
				
			this.TotalDue = businessObject.TotalDue;
				
				
	if (businessObject.Comment != null )
				this.Comment = (String)businessObject.Comment;
			this.rowguid = businessObject.rowguid;
				
				this.ModifiedDate = (DateTime)businessObject.ModifiedDate;
	        if (businessObject.Address != null){
	                	this.FkAddressText = businessObject.Address.AddressLine1.Trim().Replace("\t", String.Empty); 
										
										
				this.FkAddress = businessObject.Address.AddressID;
                this.FKAddressSafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.Address,"AddressID").Replace("/","-");

			}
	        if (businessObject.Address1 != null){
	                	this.FkAddress1Text = businessObject.Address1.AddressLine1.Trim().Replace("\t", String.Empty); 
										
										
				this.FkAddress1 = businessObject.Address1.AddressID;
                this.FKAddress1SafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.Address1,"AddressID").Replace("/","-");

			}
	        if (businessObject.Customer != null){
	                	this.FkCustomerText = businessObject.Customer.Title != null ? businessObject.Customer.Title.ToString() : "";; 
										
				this.FkCustomer = businessObject.Customer.CustomerID;
                this.FKCustomerSafeKey  = SFSdotNet.Framework.Entities.Utils.GetKey(businessObject.Customer,"CustomerID").Replace("/","-");

			}
           
        }
	}
}
